package com.lcz.authority.admin.mapper;

import com.lcz.authority.common.core.mybatis.BaseMapperX;
import com.lcz.authority.common.core.mybatis.LambdaQueryWrapperX;
import com.lcz.authority.common.core.page.PageResult;
import com.lcz.authority.common.domain.entity.SysLoginLogEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author lcz
 * @desc 系统访问日志情况信息 数据层
 * @mail lcz_0130@163.com
 * @date 2024/05/06
 */
@Mapper
public interface SysLoginLogMapper extends BaseMapperX<SysLoginLogEntity> {

    default PageResult<SysLoginLogEntity> selectLogininforPage(SysLoginLogEntity logininfor) {
        return selectPage(new LambdaQueryWrapperX<SysLoginLogEntity>()
                .eqIfPresent(SysLoginLogEntity::getUserId, logininfor.getUserId())
                .eqIfPresent(SysLoginLogEntity::getUserName, logininfor.getUserName())
                .eqIfPresent(SysLoginLogEntity::getStatus, logininfor.getStatus())
                .betweenIfPresent(SysLoginLogEntity::getLoginTime, logininfor.getParams())
                .orderByDesc(SysLoginLogEntity::getInfoId)
        );
    }


    /**
     * 查询系统登录日志集合
     *
     * @param logininfor 访问日志对象
     * @return 登录记录集合
     */
    default List<SysLoginLogEntity> selectLogininforList(SysLoginLogEntity logininfor) {
        return selectList(new LambdaQueryWrapperX<SysLoginLogEntity>()
                .eqIfPresent(SysLoginLogEntity::getStatus, logininfor.getStatus())
                .likeIfPresent(SysLoginLogEntity::getUserName, logininfor.getUserName())
                .eqIfPresent(SysLoginLogEntity::getUserId, logininfor.getUserId()));
    }


    /**
     * 清空系统登录日志
     *
     * @return 结果
     */
    @Update("truncate table sys_log_login")
    int cleanLogininfor();


}
